LoginWindow = function() {
	this.username = new Ext.form.TextField({
		fieldLabel: 'Имя пользователя',
		labelStyle : 'float:left;width:130px; text-align:right;',
		emptyText: '',
		width: 120,
		validationEvent: false,
        validateOnBlur: false,
		msgTarget: 'under',
		displayField: 'username',
		name : 'username',
		mode: 'local',
		listeners:{
			valid: this.syncShadow,
			invalid: this.syncShadow,
			scope: this
		}
	});
	
	this.password = new Ext.form.TextField({
		fieldLabel: 'Пароль',
		labelStyle : 'float:left;width:130px; text-align:right;',
		inputType : 'password', 
		emptyText: '',
		width: 120,
		validationEvent: false,
        validateOnBlur: false,
		msgTarget: 'under',
		displayField: 'password',
		name: 'password',
		mode: 'local',
		listeners:{
			valid: this.syncShadow,
			invalid: this.syncShadow,
			scope: this
		}
	});
	
	
	this.form = new Ext.FormPanel({
        labelAlign:'top',
		url:'login.php',
        items:[this.username,this.password],
		waitMsgTarget: true,
        border: false,
        bodyStyle:'background:transparent;padding:10px;'
    });
	
	LoginWindow.superclass.constructor.call(this, {
        title: 'Войти',
        iconCls: 'loginbtn',
        id: 'login-window',
        autoHeight: true,
        width: 300,
        resizable: false,
        plain:true,
        modal: true,
        y: 100,
        autoScroll: true,
        closeAction: 'hide',

        buttons:[{
            text: 'Войти',
            handler: this.submitForm,
            scope: this
        },{
            text: 'Отмена',
            handler: this.hide.createDelegate(this, [])
        }],

        items: this.form
    });
	
	this.addEvents({add:true});
}

Ext.extend(LoginWindow, Ext.Window, {

    show : function(){
        LoginWindow.superclass.show.apply(this, arguments);
    },
	submitForm: function() {
		this.form.getForm().submit({url:'login.php', waitMsg:'Авторизация...',success:function(form,action) {this.onSuccess();},failure: function(form,action) {this.onError(action.result);},scope:this});
	},
	onSuccess: function() {
		this.hide();
		checkLogin();
	},
	onError: function(res){
		this.password.markInvalid("Неверное имя пользователя или пароль");
	}
	
	
});